package com.gsy;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Random;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main(String[] args) {
        int len = 10000;
        double arr[] = generator(0.0001,len);
//        HW3 aa = new HW3();
//        aa.clone()
        double sum = 0;
        for (double v : arr) {
            sum += v;
        }
        System.out.println(sum/len);
        Arrays.sort(arr);
        double per = 1.0/len;
        double p = 1.0/len;
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < len; i++) {
            stringBuffer.append(arr[i]+","+per);
            stringBuffer.append("\n");
            System.out.printf("%20f,%f",arr[i],per);
            System.out.println();
            per = per+p;
        }
        try {
            FileUtils.write(new File("hw3.csv"),stringBuffer.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
//        System.out.println(Arrays);

    }
    public static double expDistribution(double lambda, Random random) {
        return -Math.log(1- random.nextDouble())/lambda;
    }
    public static double[] generator(double lambda,int length){
        Random random = new SecureRandom();
        double re[] = new double[length];
        for (int i = 0; i < length; i++) {
            re[i] = expDistribution(lambda,random);
        }
        return re;
    }

}
